package com.chengjj.kings.core.util;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @Author: 成俊杰
 * @CreateDate: 2019/3/8
 * @Version: 1.0
 * @Description: 非空判断工具类
 */
public class ValidateUtil {
    public ValidateUtil() {
    }

    /**
     * 判断是否不为空
     *
     * @param o
     * @return
     */
    public static boolean isNotEmpty(Object o) {
        return !isEmpty(o);
    }

    /**
     * 判断是否为空
     *
     * @param o
     * @return
     */
    public static boolean isEmpty(Object o) {
        if (o == null) {
            return true;
        } else {
            if (o instanceof String && o.toString().trim().equals("")) {
                return true;
            } else if (o instanceof List && ((List) o).size() == 0) {
                return true;
            } else if (o instanceof Map && ((Map) o).size() == 0) {
                return true;
            } else if (o instanceof Set && ((Set) o).size() == 0) {
                return true;
            } else if (o instanceof Object[] && ((Object[]) o).length == 0) {
                return true;
            } else if (o instanceof int[] && ((int[]) o).length == 0) {
                return true;
            } else if (o instanceof long[] && (((long[]) o)).length == 0) {
                return true;
            }
            return false;
        }
    }

    /**
     * 判断对象数组中是否存在空对象
     *
     * @param os
     * @return
     */
    public static boolean isOneEmpty(Object... os) {
        Object[] var1 = os;
        int var2 = os.length;
        for (int var3 = 0; var3 < var2; var3++) {
            Object o = var1[var3];
            if (isEmpty(o)) {
                return true;
            }
        }
        return false;
    }

    /**
     * 判断对象数组是否全为空
     *
     * @param objects
     * @return
     */
    public static boolean isAllEmpty(Object... objects) {
        Object[] var1 = objects;
        int var2 = var1.length;
        for (int var3 = 0; var3 < var2; var3++) {
            Object o = var1[var3];
            if (!isEmpty(o)) {
                return false;
            }
        }
        return true;
    }
}
